load(
    "@com_github_mvukov_rules_ros2//ros2:interfaces.bzl",
    "cpp_ros2_interface_library",
    "py_ros2_interface_library",
    "ros2_interface_library",
)
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_license//rules:license.bzl", "license")

license(
    name = "license",
    license_kinds = ["@rules_license//licenses/spdx:Apache-2.0"],
    license_text = "LICENSE",
)

# Exclude the tree_execution_server for now because it depends on generate_parameter_library, which
# is not yet bazelified.
TREE_EXECUTION_SERVER_SRCS = [
    "behaviortree_ros2/src/tree_execution_server.cpp",
    "behaviortree_ros2/src/bt_utils.cpp",
]

TREE_EXECUTION_SERVER_HDRS = [
    "behaviortree_ros2/include/bt_utils.hpp",
]

cc_library(
    name = "behaviortree_ros2",
    srcs = glob(
        ["behaviortree_ros2/src/**/*.cpp"],
        exclude = TREE_EXECUTION_SERVER_SRCS,
    ),
    hdrs = glob(
        ["behaviortree_ros2/include/**/*.hpp"],
        exclude = TREE_EXECUTION_SERVER_HDRS,
    ),
    includes = ["behaviortree_ros2/include"],
    visibility = ["//visibility:public"],
    deps = [
        ":cpp_btcpp_ros2_interfaces",
        "@behaviortree_cpp",
        "@boost.signals2",
        "@ros2_rclcpp//:rclcpp",
        "@ros2_rclcpp//:rclcpp_action",
    ],
)

ros2_interface_library(
    name = "btcpp_ros2_interfaces",
    srcs = glob([
        "btcpp_ros2_interfaces/action/*.action",
        "btcpp_ros2_interfaces/msg/*.msg",
    ]),
    visibility = ["//visibility:public"],
    deps = ["@ros2_rcl_interfaces//:action_msgs"],
)

cpp_ros2_interface_library(
    name = "cpp_btcpp_ros2_interfaces",
    visibility = ["//visibility:public"],
    deps = [":btcpp_ros2_interfaces"],
)

py_ros2_interface_library(
    name = "py_btcpp_ros2_interfaces",
    visibility = ["//visibility:public"],
    deps = [":btcpp_ros2_interfaces"],
)

exports_files(
    srcs = ["behaviortree_ros2/src/bt_executor_parameters.yaml"],
    visibility = ["//visibility:public"],
)
